package com.eralink.unionuhfreader.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputType;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.eralink.unionuhfreader.R;

public class CommonDialog extends Dialog {
    private View.OnClickListener listener;
    private EditText vip;
    private TextView tvCancel;
    private TextView tvConfirm;
    private String title;
    private TextView tv_tip;
    private int layoutid=-1;
    private EditText vip_number_cause;
   String  descreption;
   private TextView tv_description;
    private int  inputtype= InputType.TYPE_CLASS_TEXT;
    public CommonDialog(@NonNull Context var1) {
        super(var1, R.style.DialogStyle);
    }
    public CommonDialog(@NonNull Context var1,String title) {
        super(var1, R.style.DialogStyle);
        this.title=title;
    }
    public CommonDialog(@NonNull Context var1,String title,String discreption) {
        super(var1, R.style.DialogStyle);
        this.title=title;
        descreption=discreption;
    }

    public CommonDialog(@NonNull Context var1,String title,int layoutid,int inputtype) {
        super(var1, R.style.DialogStyle);
        this.title=title;
        this.layoutid=layoutid;
        this.inputtype=inputtype;
    }
    public CommonDialog(@NonNull Context var1,String title,int layoutid) {
        super(var1, R.style.DialogStyle);
        this.title=title;
        this.layoutid=layoutid;
    }
    public CommonDialog(@NonNull Context var1, int var2) {
        super(var1, var2);
    }

    private void initAction() {

    }

    private void initView() {
        vip = findViewById(R.id.vip_number);
        tv_tip=findViewById(R.id.tip);
        vip_number_cause=findViewById(R.id.vip_number);
        if (title!=null){
            tv_tip.setText(title);
        }
        if (inputtype!=InputType.TYPE_CLASS_TEXT){
            vip.setInputType(inputtype);
        }
        tv_description=findViewById(R.id.descreption);
        if (descreption!=null&&!descreption.equals("")){
            tv_description.setText(descreption);
            tv_description.setVisibility(View.VISIBLE);
            vip_number_cause.setVisibility(View.GONE);
        }else{
            tv_description.setVisibility(View.GONE);
            vip_number_cause.setVisibility(View.VISIBLE);
        }
        this.tvCancel = (TextView) this.findViewById(R.id.tv_cancel);
        this.tvConfirm = (TextView) this.findViewById(R.id.tv_confirm);
        if (this.listener != null) {
            this.tvCancel.setOnClickListener(listener);
            this.tvConfirm.setOnClickListener(listener);
        }
        vip.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if(s.length() == 11){
                    tvConfirm.setAlpha(1);
                    tvConfirm.setEnabled(true);
                }else {
                    tvConfirm.setAlpha(0.5f);
                    tvConfirm.setEnabled(true);
                }
               tvConfirm.setTag(vip.getText().toString());
            }
        });
    }

    public String getStr() {
        return this.vip.getText().toString();
    }

    public void  setStr(String val){
        if (vip!=null){
            vip.setText(val);
        }
    }
    public String getCause(){
        return this.vip_number_cause.getText().toString();
    }
    @Override
    protected void onCreate(Bundle var1) {
        super.onCreate(var1);
        if (layoutid==-1){
            this.setContentView(R.layout.dialog_vip_pay);
        }else{
            this.setContentView(layoutid);
        }

        this.setCancelable(false);
        this.initView();
        this.initAction();
    }

    public void  setInputType(int type){
        this.inputtype=type;
    }
    public CommonDialog setOnClickListener(View.OnClickListener var1) {
        this.listener = var1;
        return this;
    }

    public void show() {
        super.show();
    }
}
